package com.example.demo5.Controller;

import com.example.demo5.AccessToken.PrividerToken;
import com.example.demo5.Privider.AccessPrivider;
import com.example.demo5.model.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class AccessTokenController {
    @Autowired
    private PrividerToken prividerToken;

    @Autowired
    private AccessPrivider accessPrivider;

    @Autowired
    private User user;

    @GetMapping("/callback")
    public String callback(@RequestParam(name = "code") String code,
                           @RequestParam(name = "state") String state) {

        prividerToken.setClient_id("你的客户ID");
        prividerToken.setCode(code);
        prividerToken.setRedirect_uri("http://localhost:8080/callback");
        prividerToken.setState(state);
        prividerToken.setClient_Secret("你的密钥");
        String Token = accessPrivider.getToken(prividerToken);
        user = accessPrivider.getUser(Token);
        user.getEmail();


        return "redirect:/";
    }


}
